/**
 * 工单通知管理初始化
 */
var WorkNotice = {
    id: "WorkNoticeTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
WorkNotice.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '客户姓名', field: 'userName', visible: true, align: 'center', valign: 'middle'},
        {title: '客户电话', field: 'userPhone', visible: true, align: 'center', valign: 'middle'},
        {title: '地址', field: 'address', visible: true, align: 'center', valign: 'middle'},
        {title: '工单类型', field: 'workTypeValue', visible: true, align: 'center', valign: 'middle'},
        {title: '创建日期', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
        {title: '安装人员', field: 'setupName', visible: true, align: 'center', valign: 'middle'},
        {title: '处理日期', field: 'dealTime', visible: true, align: 'center', valign: 'middle'},
        {title: '工单状态', field: 'statusValue', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
WorkNotice.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        WorkNotice.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加工单通知
 */
WorkNotice.openAddWorkNotice = function () {
    var index = layer.open({
        type: 2,
        title: '添加工单通知',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/workNotice/workNotice_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看工单通知详情
 */
WorkNotice.openWorkNoticeDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '工单通知详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/workNotice/workNotice_update/' + WorkNotice.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除工单通知
 */
WorkNotice.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/workNotice/delete", function (data) {
            Feng.success("删除成功!");
            WorkNotice.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("workNoticeId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询工单通知列表
 */
WorkNotice.search = function () {
    var queryData = {};
    queryData['orderNo'] = $("#orderNo").val();
    queryData['status'] = $("#status").val();
    queryData['userName'] = $("#userName").val();
    queryData['userPhone'] = $("#userPhone").val();
    queryData['address'] = $("#address").val();
    WorkNotice.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = WorkNotice.initColumn();
    var table = new BSTable(WorkNotice.id, "/workNotice/list", defaultColunms);
    table.setPaginationType("server");
    table.init();
    WorkNotice.table = table;
});
